{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup Data Fetching"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ta\n",
    "\n",
    "import pandas as pd\n",
    "import tensortrade.env.default as default\n",
    "\n",
    "from tensortrade.data.cdd import CryptoDataDownload\n",
    "from tensortrade.feed.core import Stream, DataFeed, NameSpace\n",
    "from tensortrade.oms.instruments import USD, BTC, ETH, LTC\n",
    "from tensortrade.oms.wallets import Wallet, Portfolio\n",
    "from tensortrade.oms.exchanges import Exchange\n",
    "from tensortrade.oms.services.execution.simulated import execute_order"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fetch Historical Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "cdd = CryptoDataDownload()\n",
    "\n",
    "bitfinex_data = pd.concat([\n",
    "    cdd.fetch(\"Bitfinex\", \"USD\", \"BTC\", \"1h\").add_prefix(\"BTC:\"),\n",
    "    cdd.fetch(\"Bitfinex\", \"USD\", \"ETH\", \"1h\").add_prefix(\"ETH:\")\n",
    "], axis=1)\n",
    "\n",
    "bitstamp_data = pd.concat([\n",
    "    cdd.fetch(\"Bitstamp\", \"USD\", \"BTC\", \"1h\").add_prefix(\"BTC:\"),\n",
    "    cdd.fetch(\"Bitstamp\", \"USD\", \"LTC\", \"1h\").add_prefix(\"LTC:\")\n",
    "], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>BTC:date</th>\n",
       "      <th>BTC:open</th>\n",
       "      <th>BTC:high</th>\n",
       "      <th>BTC:low</th>\n",
       "      <th>BTC:close</th>\n",
       "      <th>BTC:volume</th>\n",
       "      <th>ETH:date</th>\n",
       "      <th>ETH:open</th>\n",
       "      <th>ETH:high</th>\n",
       "      <th>ETH:low</th>\n",
       "      <th>ETH:close</th>\n",
       "      <th>ETH:volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-07-01 11:00:00</td>\n",
       "      <td>2505.56</td>\n",
       "      <td>2513.38</td>\n",
       "      <td>2495.12</td>\n",
       "      <td>2509.17</td>\n",
       "      <td>287000.32</td>\n",
       "      <td>2017-07-01 11:00:00</td>\n",
       "      <td>279.98</td>\n",
       "      <td>279.99</td>\n",
       "      <td>272.1</td>\n",
       "      <td>275.01</td>\n",
       "      <td>679358.87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-01 12:00:00</td>\n",
       "      <td>2509.17</td>\n",
       "      <td>2512.87</td>\n",
       "      <td>2484.99</td>\n",
       "      <td>2488.43</td>\n",
       "      <td>393142.50</td>\n",
       "      <td>2017-07-01 12:00:00</td>\n",
       "      <td>275.01</td>\n",
       "      <td>275.01</td>\n",
       "      <td>271.0</td>\n",
       "      <td>274.83</td>\n",
       "      <td>824362.87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-07-01 13:00:00</td>\n",
       "      <td>2488.43</td>\n",
       "      <td>2488.43</td>\n",
       "      <td>2454.40</td>\n",
       "      <td>2454.43</td>\n",
       "      <td>693254.01</td>\n",
       "      <td>2017-07-01 13:00:00</td>\n",
       "      <td>274.83</td>\n",
       "      <td>274.93</td>\n",
       "      <td>265.0</td>\n",
       "      <td>268.79</td>\n",
       "      <td>3010787.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-07-01 14:00:00</td>\n",
       "      <td>2454.43</td>\n",
       "      <td>2473.93</td>\n",
       "      <td>2450.83</td>\n",
       "      <td>2459.35</td>\n",
       "      <td>712864.80</td>\n",
       "      <td>2017-07-01 14:00:00</td>\n",
       "      <td>268.79</td>\n",
       "      <td>269.90</td>\n",
       "      <td>265.0</td>\n",
       "      <td>265.74</td>\n",
       "      <td>1702536.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-07-01 15:00:00</td>\n",
       "      <td>2459.35</td>\n",
       "      <td>2475.00</td>\n",
       "      <td>2450.00</td>\n",
       "      <td>2467.83</td>\n",
       "      <td>682105.41</td>\n",
       "      <td>2017-07-01 15:00:00</td>\n",
       "      <td>265.74</td>\n",
       "      <td>272.74</td>\n",
       "      <td>265.0</td>\n",
       "      <td>272.57</td>\n",
       "      <td>1500282.55</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             BTC:date  BTC:open  BTC:high  ...  ETH:low  ETH:close  ETH:volume\n",
       "0 2017-07-01 11:00:00   2505.56   2513.38  ...    272.1     275.01   679358.87\n",
       "1 2017-07-01 12:00:00   2509.17   2512.87  ...    271.0     274.83   824362.87\n",
       "2 2017-07-01 13:00:00   2488.43   2488.43  ...    265.0     268.79  3010787.99\n",
       "3 2017-07-01 14:00:00   2454.43   2473.93  ...    265.0     265.74  1702536.85\n",
       "4 2017-07-01 15:00:00   2459.35   2475.00  ...    265.0     272.57  1500282.55\n",
       "\n",
       "[5 rows x 12 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bitfinex_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>BTC:date</th>\n",
       "      <th>BTC:open</th>\n",
       "      <th>BTC:high</th>\n",
       "      <th>BTC:low</th>\n",
       "      <th>BTC:close</th>\n",
       "      <th>BTC:volume</th>\n",
       "      <th>LTC:date</th>\n",
       "      <th>LTC:open</th>\n",
       "      <th>LTC:high</th>\n",
       "      <th>LTC:low</th>\n",
       "      <th>LTC:close</th>\n",
       "      <th>LTC:volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-07-01 11:00:00</td>\n",
       "      <td>2506.50</td>\n",
       "      <td>2510.62</td>\n",
       "      <td>2495.50</td>\n",
       "      <td>2500.00</td>\n",
       "      <td>521903.70</td>\n",
       "      <td>2017-07-01 11:00:00</td>\n",
       "      <td>39.67</td>\n",
       "      <td>39.67</td>\n",
       "      <td>39.32</td>\n",
       "      <td>39.45</td>\n",
       "      <td>1957.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-07-01 12:00:00</td>\n",
       "      <td>2500.00</td>\n",
       "      <td>2503.69</td>\n",
       "      <td>2488.25</td>\n",
       "      <td>2495.62</td>\n",
       "      <td>607308.42</td>\n",
       "      <td>2017-07-01 12:00:00</td>\n",
       "      <td>39.45</td>\n",
       "      <td>39.57</td>\n",
       "      <td>39.18</td>\n",
       "      <td>39.57</td>\n",
       "      <td>2507.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-07-01 13:00:00</td>\n",
       "      <td>2495.62</td>\n",
       "      <td>2495.62</td>\n",
       "      <td>2433.59</td>\n",
       "      <td>2449.01</td>\n",
       "      <td>1421546.81</td>\n",
       "      <td>2017-07-01 13:00:00</td>\n",
       "      <td>39.57</td>\n",
       "      <td>39.57</td>\n",
       "      <td>38.80</td>\n",
       "      <td>38.90</td>\n",
       "      <td>22019.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-07-01 14:00:00</td>\n",
       "      <td>2449.01</td>\n",
       "      <td>2480.60</td>\n",
       "      <td>2438.88</td>\n",
       "      <td>2457.90</td>\n",
       "      <td>1302198.58</td>\n",
       "      <td>2017-07-01 14:00:00</td>\n",
       "      <td>38.90</td>\n",
       "      <td>39.08</td>\n",
       "      <td>38.77</td>\n",
       "      <td>39.06</td>\n",
       "      <td>30732.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-07-01 15:00:00</td>\n",
       "      <td>2457.90</td>\n",
       "      <td>2471.88</td>\n",
       "      <td>2452.10</td>\n",
       "      <td>2466.35</td>\n",
       "      <td>719666.88</td>\n",
       "      <td>2017-07-01 15:00:00</td>\n",
       "      <td>39.06</td>\n",
       "      <td>39.16</td>\n",
       "      <td>38.73</td>\n",
       "      <td>39.15</td>\n",
       "      <td>26053.18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             BTC:date  BTC:open  BTC:high  ...  LTC:low  LTC:close  LTC:volume\n",
       "0 2017-07-01 11:00:00   2506.50   2510.62  ...    39.32      39.45     1957.48\n",
       "1 2017-07-01 12:00:00   2500.00   2503.69  ...    39.18      39.57     2507.48\n",
       "2 2017-07-01 13:00:00   2495.62   2495.62  ...    38.80      38.90    22019.12\n",
       "3 2017-07-01 14:00:00   2449.01   2480.60  ...    38.77      39.06    30732.98\n",
       "4 2017-07-01 15:00:00   2457.90   2471.88  ...    38.73      39.15    26053.18\n",
       "\n",
       "[5 rows x 12 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bitstamp_data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define Exchanges\n",
    "\n",
    "An exchange needs a name, an execution service, and streams of price data in order to function properly.\n",
    "\n",
    "The setups supported right now are the simulated execution service using simulated or stochastic data. More execution services will be made available in the future, as well as price streams so that live data and execution can be supported."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "bitfinex = Exchange(\"bitfinex\", service=execute_order)(\n",
    "    Stream.source(list(bitfinex_data['BTC:close']), dtype=\"float\").rename(\"USD-BTC\"),\n",
    "    Stream.source(list(bitfinex_data['ETH:close']), dtype=\"float\").rename(\"USD-ETH\")\n",
    ")\n",
    "\n",
    "bitstamp = Exchange(\"bitstamp\", service=execute_order)(\n",
    "    Stream.source(list(bitstamp_data['BTC:close']), dtype=\"float\").rename(\"USD-BTC\"),\n",
    "    Stream.source(list(bitstamp_data['LTC:close']), dtype=\"float\").rename(\"USD-LTC\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that the exchanges have been defined we can define our features that we would like to include, excluding the prices we have provided for the exchanges."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define External Data Feed\n",
    "\n",
    "Here we will define the feed to use whatever data you would like. From financial indicators to alternative datasets, they will all have to be defined and incorporated into the `DataFeed` provided to the environment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add all features for bitstamp BTC & ETH\n",
    "bitfinex_btc = bitfinex_data.loc[:, [name.startswith(\"BTC\") for name in bitfinex_data.columns]]\n",
    "bitfinex_eth = bitfinex_data.loc[:, [name.startswith(\"ETH\") for name in bitfinex_data.columns]]\n",
    "\n",
    "ta.add_all_ta_features(\n",
    "    bitfinex_btc,\n",
    "    colprefix=\"BTC:\",\n",
    "    **{k: \"BTC:\" + k for k in ['open', 'high', 'low', 'close', 'volume']}\n",
    ")\n",
    "\n",
    "\n",
    "with NameSpace(\"bitfinex\"):\n",
    "    bitfinex_streams = [\n",
    "        Stream.source(list(bitfinex_btc[c]), dtype=\"float\").rename(c) for c in bitfinex_btc.columns\n",
    "    ]\n",
    "    bitfinex_streams += [\n",
    "        Stream.source(list(bitfinex_eth[c]), dtype=\"float\").rename(c) for c in bitfinex_eth.columns\n",
    "    ]\n",
    "    \n",
    "\n",
    "# Add all features for bitstamp BTC & LTC\n",
    "bitstamp_btc = bitstamp_data.loc[:, [name.startswith(\"BTC\") for name in bitstamp_data.columns]]  \n",
    "bitstamp_ltc = bitstamp_data.loc[:, [name.startswith(\"LTC\") for name in bitstamp_data.columns]]\n",
    "\n",
    "ta.add_all_ta_features(\n",
    "    bitstamp_ltc,\n",
    "    colprefix=\"LTC:\",\n",
    "    **{k: \"LTC:\" + k for k in ['open', 'high', 'low', 'close', 'volume']}\n",
    ")\n",
    "\n",
    "with NameSpace(\"bitstamp\"):\n",
    "    bitstamp_streams = [\n",
    "        Stream.source(list(bitstamp_btc[c]), dtype=\"float\").rename(c) for c in bitstamp_btc.columns\n",
    "    ]\n",
    "    bitstamp_streams += [\n",
    "        Stream.source(list(bitstamp_ltc[c]), dtype=\"float\").rename(c) for c in bitstamp_ltc.columns\n",
    "    ]\n",
    "\n",
    "\n",
    "feed = DataFeed(bitfinex_streams + bitstamp_streams)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bitfinex:/BTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       " 'bitfinex:/BTC:open': 2505.56,\n",
       " 'bitfinex:/BTC:high': 2513.38,\n",
       " 'bitfinex:/BTC:low': 2495.12,\n",
       " 'bitfinex:/BTC:close': 2509.17,\n",
       " 'bitfinex:/BTC:volume': 287000.32,\n",
       " 'bitfinex:/BTC:volume_adi': 462887.3781183644,\n",
       " 'bitfinex:/BTC:volume_obv': nan,\n",
       " 'bitfinex:/BTC:volume_cmf': 0.5388828039430464,\n",
       " 'bitfinex:/BTC:volume_fi': nan,\n",
       " 'bitfinex:/BTC:volume_em': nan,\n",
       " 'bitfinex:/BTC:volume_vpt': -190920.02711825827,\n",
       " 'bitfinex:/BTC:volume_nvi': 1000.0,\n",
       " 'bitfinex:/BTC:volatility_atr': 85.51648155760596,\n",
       " 'bitfinex:/BTC:volatility_bbh': 2509.17,\n",
       " 'bitfinex:/BTC:volatility_bbl': 2509.17,\n",
       " 'bitfinex:/BTC:volatility_bbm': 2509.17,\n",
       " 'bitfinex:/BTC:volatility_bbhi': 0.0,\n",
       " 'bitfinex:/BTC:volatility_bbli': 0.0,\n",
       " 'bitfinex:/BTC:volatility_kcc': 2505.89,\n",
       " 'bitfinex:/BTC:volatility_kch': 2524.15,\n",
       " 'bitfinex:/BTC:volatility_kcl': 2487.6299999999997,\n",
       " 'bitfinex:/BTC:volatility_kchi': 0.0,\n",
       " 'bitfinex:/BTC:volatility_kcli': 0.0,\n",
       " 'bitfinex:/BTC:volatility_dch': 2509.17,\n",
       " 'bitfinex:/BTC:volatility_dcl': 2509.17,\n",
       " 'bitfinex:/BTC:volatility_dchi': 0.0,\n",
       " 'bitfinex:/BTC:volatility_dcli': 0.0,\n",
       " 'bitfinex:/BTC:trend_macd': nan,\n",
       " 'bitfinex:/BTC:trend_macd_signal': nan,\n",
       " 'bitfinex:/BTC:trend_macd_diff': nan,\n",
       " 'bitfinex:/BTC:trend_ema_fast': nan,\n",
       " 'bitfinex:/BTC:trend_ema_slow': nan,\n",
       " 'bitfinex:/BTC:trend_adx': 0.0,\n",
       " 'bitfinex:/BTC:trend_adx_pos': 0.0,\n",
       " 'bitfinex:/BTC:trend_adx_neg': 0.0,\n",
       " 'bitfinex:/BTC:trend_vortex_ind_pos': nan,\n",
       " 'bitfinex:/BTC:trend_vortex_ind_neg': nan,\n",
       " 'bitfinex:/BTC:trend_vortex_diff': nan,\n",
       " 'bitfinex:/BTC:trend_trix': nan,\n",
       " 'bitfinex:/BTC:trend_mass_index': 0.0,\n",
       " 'bitfinex:/BTC:trend_cci': nan,\n",
       " 'bitfinex:/BTC:trend_dpo': 4963.073762705523,\n",
       " 'bitfinex:/BTC:trend_kst': -664.2012654186367,\n",
       " 'bitfinex:/BTC:trend_kst_sig': -664.2012654186367,\n",
       " 'bitfinex:/BTC:trend_kst_diff': 0.0,\n",
       " 'bitfinex:/BTC:trend_ichimoku_a': 2504.25,\n",
       " 'bitfinex:/BTC:trend_ichimoku_b': 2504.25,\n",
       " 'bitfinex:/BTC:trend_visual_ichimoku_a': 7460.129960014917,\n",
       " 'bitfinex:/BTC:trend_visual_ichimoku_b': 7449.72498449202,\n",
       " 'bitfinex:/BTC:trend_aroon_up': 4.0,\n",
       " 'bitfinex:/BTC:trend_aroon_down': 4.0,\n",
       " 'bitfinex:/BTC:trend_aroon_ind': 0.0,\n",
       " 'bitfinex:/BTC:momentum_rsi': nan,\n",
       " 'bitfinex:/BTC:momentum_mfi': nan,\n",
       " 'bitfinex:/BTC:momentum_tsi': -100.0,\n",
       " 'bitfinex:/BTC:momentum_uo': 0.2822915537138003,\n",
       " 'bitfinex:/BTC:momentum_stoch': 76.94414019715232,\n",
       " 'bitfinex:/BTC:momentum_stoch_signal': 76.94414019715232,\n",
       " 'bitfinex:/BTC:momentum_wr': -23.055859802847678,\n",
       " 'bitfinex:/BTC:momentum_ao': 0.0,\n",
       " 'bitfinex:/BTC:momentum_kama': nan,\n",
       " 'bitfinex:/BTC:others_dr': -66.42012654186367,\n",
       " 'bitfinex:/BTC:others_dlr': nan,\n",
       " 'bitfinex:/BTC:others_cr': 0.0,\n",
       " 'bitfinex:/ETH:date': Timestamp('2017-07-01 11:00:00'),\n",
       " 'bitfinex:/ETH:open': 279.98,\n",
       " 'bitfinex:/ETH:high': 279.99,\n",
       " 'bitfinex:/ETH:low': 272.1,\n",
       " 'bitfinex:/ETH:close': 275.01,\n",
       " 'bitfinex:/ETH:volume': 679358.87,\n",
       " 'bitstamp:/BTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       " 'bitstamp:/BTC:open': 2506.5,\n",
       " 'bitstamp:/BTC:high': 2510.62,\n",
       " 'bitstamp:/BTC:low': 2495.5,\n",
       " 'bitstamp:/BTC:close': 2500.0,\n",
       " 'bitstamp:/BTC:volume': 521903.7,\n",
       " 'bitstamp:/LTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       " 'bitstamp:/LTC:open': 39.67,\n",
       " 'bitstamp:/LTC:high': 39.67,\n",
       " 'bitstamp:/LTC:low': 39.32,\n",
       " 'bitstamp:/LTC:close': 39.45,\n",
       " 'bitstamp:/LTC:volume': 1957.48,\n",
       " 'bitstamp:/LTC:volume_adi': 5133.608444728016,\n",
       " 'bitstamp:/LTC:volume_obv': nan,\n",
       " 'bitstamp:/LTC:volume_cmf': -0.2571428571428455,\n",
       " 'bitstamp:/LTC:volume_fi': nan,\n",
       " 'bitstamp:/LTC:volume_em': nan,\n",
       " 'bitstamp:/LTC:volume_vpt': -895.4321955984681,\n",
       " 'bitstamp:/LTC:volume_nvi': 1000.0,\n",
       " 'bitstamp:/LTC:volatility_atr': 1.4838450097847482,\n",
       " 'bitstamp:/LTC:volatility_bbh': 39.45,\n",
       " 'bitstamp:/LTC:volatility_bbl': 39.45,\n",
       " 'bitstamp:/LTC:volatility_bbm': 39.45,\n",
       " 'bitstamp:/LTC:volatility_bbhi': 0.0,\n",
       " 'bitstamp:/LTC:volatility_bbli': 0.0,\n",
       " 'bitstamp:/LTC:volatility_kcc': 39.480000000000004,\n",
       " 'bitstamp:/LTC:volatility_kch': 39.830000000000005,\n",
       " 'bitstamp:/LTC:volatility_kcl': 39.13,\n",
       " 'bitstamp:/LTC:volatility_kchi': 0.0,\n",
       " 'bitstamp:/LTC:volatility_kcli': 0.0,\n",
       " 'bitstamp:/LTC:volatility_dch': 39.45,\n",
       " 'bitstamp:/LTC:volatility_dcl': 39.45,\n",
       " 'bitstamp:/LTC:volatility_dchi': 0.0,\n",
       " 'bitstamp:/LTC:volatility_dcli': 0.0,\n",
       " 'bitstamp:/LTC:trend_macd': nan,\n",
       " 'bitstamp:/LTC:trend_macd_signal': nan,\n",
       " 'bitstamp:/LTC:trend_macd_diff': nan,\n",
       " 'bitstamp:/LTC:trend_ema_fast': nan,\n",
       " 'bitstamp:/LTC:trend_ema_slow': nan,\n",
       " 'bitstamp:/LTC:trend_adx': 0.0,\n",
       " 'bitstamp:/LTC:trend_adx_pos': 0.0,\n",
       " 'bitstamp:/LTC:trend_adx_neg': 0.0,\n",
       " 'bitstamp:/LTC:trend_vortex_ind_pos': nan,\n",
       " 'bitstamp:/LTC:trend_vortex_ind_neg': nan,\n",
       " 'bitstamp:/LTC:trend_vortex_diff': nan,\n",
       " 'bitstamp:/LTC:trend_trix': nan,\n",
       " 'bitstamp:/LTC:trend_mass_index': 0.0,\n",
       " 'bitstamp:/LTC:trend_cci': nan,\n",
       " 'bitstamp:/LTC:trend_dpo': 41.511479785526944,\n",
       " 'bitstamp:/LTC:trend_kst': -512.7312383060929,\n",
       " 'bitstamp:/LTC:trend_kst_sig': -512.7312383060929,\n",
       " 'bitstamp:/LTC:trend_kst_diff': 0.0,\n",
       " 'bitstamp:/LTC:trend_ichimoku_a': 39.495000000000005,\n",
       " 'bitstamp:/LTC:trend_ichimoku_b': 39.495000000000005,\n",
       " 'bitstamp:/LTC:trend_visual_ichimoku_a': 80.84515204884308,\n",
       " 'bitstamp:/LTC:trend_visual_ichimoku_b': 80.77039939728148,\n",
       " 'bitstamp:/LTC:trend_aroon_up': 4.0,\n",
       " 'bitstamp:/LTC:trend_aroon_down': 4.0,\n",
       " 'bitstamp:/LTC:trend_aroon_ind': 0.0,\n",
       " 'bitstamp:/LTC:momentum_rsi': nan,\n",
       " 'bitstamp:/LTC:momentum_mfi': nan,\n",
       " 'bitstamp:/LTC:momentum_tsi': -100.0,\n",
       " 'bitstamp:/LTC:momentum_uo': 0.31218871344045224,\n",
       " 'bitstamp:/LTC:momentum_stoch': 37.14285714285772,\n",
       " 'bitstamp:/LTC:momentum_stoch_signal': 37.14285714285772,\n",
       " 'bitstamp:/LTC:momentum_wr': -62.85714285714228,\n",
       " 'bitstamp:/LTC:momentum_ao': 0.0,\n",
       " 'bitstamp:/LTC:momentum_kama': nan,\n",
       " 'bitstamp:/LTC:others_dr': -51.27312383060929,\n",
       " 'bitstamp:/LTC:others_dlr': nan,\n",
       " 'bitstamp:/LTC:others_cr': 0.0}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feed.next()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Portfolio\n",
    "\n",
    "Make the portfolio using the any combinations of exchanges and intruments that the exchange supports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "portfolio = Portfolio(USD, [\n",
    "    Wallet(bitfinex, 10000 * USD),\n",
    "    Wallet(bitfinex, 10 * BTC),\n",
    "    Wallet(bitfinex, 5 * ETH),\n",
    "    Wallet(bitstamp, 1000 * USD),\n",
    "    Wallet(bitstamp, 5 * BTC),\n",
    "    Wallet(bitstamp, 3 * LTC),\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "env = default.create(\n",
    "    portfolio=portfolio,\n",
    "    action_scheme=\"managed-risk\",\n",
    "    reward_scheme=\"simple\",\n",
    "    feed=feed,\n",
    "    window_size=15,\n",
    "    enable_logger=False\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'internal': {'bitfinex:/USD-BTC': 2509.17,\n",
       "  'bitfinex:/USD-ETH': 275.01,\n",
       "  'bitfinex:/USD:/free': 10000.0,\n",
       "  'bitfinex:/USD:/locked': 0.0,\n",
       "  'bitfinex:/USD:/total': 10000.0,\n",
       "  'bitfinex:/BTC:/free': 10.0,\n",
       "  'bitfinex:/BTC:/locked': 0.0,\n",
       "  'bitfinex:/BTC:/total': 10.0,\n",
       "  'bitfinex:/BTC:/worth': 25091.7,\n",
       "  'bitfinex:/ETH:/free': 5.0,\n",
       "  'bitfinex:/ETH:/locked': 0.0,\n",
       "  'bitfinex:/ETH:/total': 5.0,\n",
       "  'bitfinex:/ETH:/worth': 1375.05,\n",
       "  'bitstamp:/USD-BTC': 2500.0,\n",
       "  'bitstamp:/USD-LTC': 39.45,\n",
       "  'bitstamp:/USD:/free': 1000.0,\n",
       "  'bitstamp:/USD:/locked': 0.0,\n",
       "  'bitstamp:/USD:/total': 1000.0,\n",
       "  'bitstamp:/BTC:/free': 5.0,\n",
       "  'bitstamp:/BTC:/locked': 0.0,\n",
       "  'bitstamp:/BTC:/total': 5.0,\n",
       "  'bitstamp:/BTC:/worth': 12500.0,\n",
       "  'bitstamp:/LTC:/free': 3.0,\n",
       "  'bitstamp:/LTC:/locked': 0.0,\n",
       "  'bitstamp:/LTC:/total': 3.0,\n",
       "  'bitstamp:/LTC:/worth': 118.35000000000001,\n",
       "  'net_worth': 50085.1},\n",
       " 'external': {'bitfinex:/BTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       "  'bitfinex:/BTC:open': 2505.56,\n",
       "  'bitfinex:/BTC:high': 2513.38,\n",
       "  'bitfinex:/BTC:low': 2495.12,\n",
       "  'bitfinex:/BTC:close': 2509.17,\n",
       "  'bitfinex:/BTC:volume': 287000.32,\n",
       "  'bitfinex:/BTC:volume_adi': 462887.3781183644,\n",
       "  'bitfinex:/BTC:volume_obv': nan,\n",
       "  'bitfinex:/BTC:volume_cmf': 0.5388828039430464,\n",
       "  'bitfinex:/BTC:volume_fi': nan,\n",
       "  'bitfinex:/BTC:volume_em': nan,\n",
       "  'bitfinex:/BTC:volume_vpt': -190920.02711825827,\n",
       "  'bitfinex:/BTC:volume_nvi': 1000.0,\n",
       "  'bitfinex:/BTC:volatility_atr': 85.51648155760596,\n",
       "  'bitfinex:/BTC:volatility_bbh': 2509.17,\n",
       "  'bitfinex:/BTC:volatility_bbl': 2509.17,\n",
       "  'bitfinex:/BTC:volatility_bbm': 2509.17,\n",
       "  'bitfinex:/BTC:volatility_bbhi': 0.0,\n",
       "  'bitfinex:/BTC:volatility_bbli': 0.0,\n",
       "  'bitfinex:/BTC:volatility_kcc': 2505.89,\n",
       "  'bitfinex:/BTC:volatility_kch': 2524.15,\n",
       "  'bitfinex:/BTC:volatility_kcl': 2487.6299999999997,\n",
       "  'bitfinex:/BTC:volatility_kchi': 0.0,\n",
       "  'bitfinex:/BTC:volatility_kcli': 0.0,\n",
       "  'bitfinex:/BTC:volatility_dch': 2509.17,\n",
       "  'bitfinex:/BTC:volatility_dcl': 2509.17,\n",
       "  'bitfinex:/BTC:volatility_dchi': 0.0,\n",
       "  'bitfinex:/BTC:volatility_dcli': 0.0,\n",
       "  'bitfinex:/BTC:trend_macd': nan,\n",
       "  'bitfinex:/BTC:trend_macd_signal': nan,\n",
       "  'bitfinex:/BTC:trend_macd_diff': nan,\n",
       "  'bitfinex:/BTC:trend_ema_fast': nan,\n",
       "  'bitfinex:/BTC:trend_ema_slow': nan,\n",
       "  'bitfinex:/BTC:trend_adx': 0.0,\n",
       "  'bitfinex:/BTC:trend_adx_pos': 0.0,\n",
       "  'bitfinex:/BTC:trend_adx_neg': 0.0,\n",
       "  'bitfinex:/BTC:trend_vortex_ind_pos': nan,\n",
       "  'bitfinex:/BTC:trend_vortex_ind_neg': nan,\n",
       "  'bitfinex:/BTC:trend_vortex_diff': nan,\n",
       "  'bitfinex:/BTC:trend_trix': nan,\n",
       "  'bitfinex:/BTC:trend_mass_index': 0.0,\n",
       "  'bitfinex:/BTC:trend_cci': nan,\n",
       "  'bitfinex:/BTC:trend_dpo': 4963.073762705523,\n",
       "  'bitfinex:/BTC:trend_kst': -664.2012654186367,\n",
       "  'bitfinex:/BTC:trend_kst_sig': -664.2012654186367,\n",
       "  'bitfinex:/BTC:trend_kst_diff': 0.0,\n",
       "  'bitfinex:/BTC:trend_ichimoku_a': 2504.25,\n",
       "  'bitfinex:/BTC:trend_ichimoku_b': 2504.25,\n",
       "  'bitfinex:/BTC:trend_visual_ichimoku_a': 7460.129960014917,\n",
       "  'bitfinex:/BTC:trend_visual_ichimoku_b': 7449.72498449202,\n",
       "  'bitfinex:/BTC:trend_aroon_up': 4.0,\n",
       "  'bitfinex:/BTC:trend_aroon_down': 4.0,\n",
       "  'bitfinex:/BTC:trend_aroon_ind': 0.0,\n",
       "  'bitfinex:/BTC:momentum_rsi': nan,\n",
       "  'bitfinex:/BTC:momentum_mfi': nan,\n",
       "  'bitfinex:/BTC:momentum_tsi': -100.0,\n",
       "  'bitfinex:/BTC:momentum_uo': 0.2822915537138003,\n",
       "  'bitfinex:/BTC:momentum_stoch': 76.94414019715232,\n",
       "  'bitfinex:/BTC:momentum_stoch_signal': 76.94414019715232,\n",
       "  'bitfinex:/BTC:momentum_wr': -23.055859802847678,\n",
       "  'bitfinex:/BTC:momentum_ao': 0.0,\n",
       "  'bitfinex:/BTC:momentum_kama': nan,\n",
       "  'bitfinex:/BTC:others_dr': -66.42012654186367,\n",
       "  'bitfinex:/BTC:others_dlr': nan,\n",
       "  'bitfinex:/BTC:others_cr': 0.0,\n",
       "  'bitfinex:/ETH:date': Timestamp('2017-07-01 11:00:00'),\n",
       "  'bitfinex:/ETH:open': 279.98,\n",
       "  'bitfinex:/ETH:high': 279.99,\n",
       "  'bitfinex:/ETH:low': 272.1,\n",
       "  'bitfinex:/ETH:close': 275.01,\n",
       "  'bitfinex:/ETH:volume': 679358.87,\n",
       "  'bitstamp:/BTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       "  'bitstamp:/BTC:open': 2506.5,\n",
       "  'bitstamp:/BTC:high': 2510.62,\n",
       "  'bitstamp:/BTC:low': 2495.5,\n",
       "  'bitstamp:/BTC:close': 2500.0,\n",
       "  'bitstamp:/BTC:volume': 521903.7,\n",
       "  'bitstamp:/LTC:date': Timestamp('2017-07-01 11:00:00'),\n",
       "  'bitstamp:/LTC:open': 39.67,\n",
       "  'bitstamp:/LTC:high': 39.67,\n",
       "  'bitstamp:/LTC:low': 39.32,\n",
       "  'bitstamp:/LTC:close': 39.45,\n",
       "  'bitstamp:/LTC:volume': 1957.48,\n",
       "  'bitstamp:/LTC:volume_adi': 5133.608444728016,\n",
       "  'bitstamp:/LTC:volume_obv': nan,\n",
       "  'bitstamp:/LTC:volume_cmf': -0.2571428571428455,\n",
       "  'bitstamp:/LTC:volume_fi': nan,\n",
       "  'bitstamp:/LTC:volume_em': nan,\n",
       "  'bitstamp:/LTC:volume_vpt': -895.4321955984681,\n",
       "  'bitstamp:/LTC:volume_nvi': 1000.0,\n",
       "  'bitstamp:/LTC:volatility_atr': 1.4838450097847482,\n",
       "  'bitstamp:/LTC:volatility_bbh': 39.45,\n",
       "  'bitstamp:/LTC:volatility_bbl': 39.45,\n",
       "  'bitstamp:/LTC:volatility_bbm': 39.45,\n",
       "  'bitstamp:/LTC:volatility_bbhi': 0.0,\n",
       "  'bitstamp:/LTC:volatility_bbli': 0.0,\n",
       "  'bitstamp:/LTC:volatility_kcc': 39.480000000000004,\n",
       "  'bitstamp:/LTC:volatility_kch': 39.830000000000005,\n",
       "  'bitstamp:/LTC:volatility_kcl': 39.13,\n",
       "  'bitstamp:/LTC:volatility_kchi': 0.0,\n",
       "  'bitstamp:/LTC:volatility_kcli': 0.0,\n",
       "  'bitstamp:/LTC:volatility_dch': 39.45,\n",
       "  'bitstamp:/LTC:volatility_dcl': 39.45,\n",
       "  'bitstamp:/LTC:volatility_dchi': 0.0,\n",
       "  'bitstamp:/LTC:volatility_dcli': 0.0,\n",
       "  'bitstamp:/LTC:trend_macd': nan,\n",
       "  'bitstamp:/LTC:trend_macd_signal': nan,\n",
       "  'bitstamp:/LTC:trend_macd_diff': nan,\n",
       "  'bitstamp:/LTC:trend_ema_fast': nan,\n",
       "  'bitstamp:/LTC:trend_ema_slow': nan,\n",
       "  'bitstamp:/LTC:trend_adx': 0.0,\n",
       "  'bitstamp:/LTC:trend_adx_pos': 0.0,\n",
       "  'bitstamp:/LTC:trend_adx_neg': 0.0,\n",
       "  'bitstamp:/LTC:trend_vortex_ind_pos': nan,\n",
       "  'bitstamp:/LTC:trend_vortex_ind_neg': nan,\n",
       "  'bitstamp:/LTC:trend_vortex_diff': nan,\n",
       "  'bitstamp:/LTC:trend_trix': nan,\n",
       "  'bitstamp:/LTC:trend_mass_index': 0.0,\n",
       "  'bitstamp:/LTC:trend_cci': nan,\n",
       "  'bitstamp:/LTC:trend_dpo': 41.511479785526944,\n",
       "  'bitstamp:/LTC:trend_kst': -512.7312383060929,\n",
       "  'bitstamp:/LTC:trend_kst_sig': -512.7312383060929,\n",
       "  'bitstamp:/LTC:trend_kst_diff': 0.0,\n",
       "  'bitstamp:/LTC:trend_ichimoku_a': 39.495000000000005,\n",
       "  'bitstamp:/LTC:trend_ichimoku_b': 39.495000000000005,\n",
       "  'bitstamp:/LTC:trend_visual_ichimoku_a': 80.84515204884308,\n",
       "  'bitstamp:/LTC:trend_visual_ichimoku_b': 80.77039939728148,\n",
       "  'bitstamp:/LTC:trend_aroon_up': 4.0,\n",
       "  'bitstamp:/LTC:trend_aroon_down': 4.0,\n",
       "  'bitstamp:/LTC:trend_aroon_ind': 0.0,\n",
       "  'bitstamp:/LTC:momentum_rsi': nan,\n",
       "  'bitstamp:/LTC:momentum_mfi': nan,\n",
       "  'bitstamp:/LTC:momentum_tsi': -100.0,\n",
       "  'bitstamp:/LTC:momentum_uo': 0.31218871344045224,\n",
       "  'bitstamp:/LTC:momentum_stoch': 37.14285714285772,\n",
       "  'bitstamp:/LTC:momentum_stoch_signal': 37.14285714285772,\n",
       "  'bitstamp:/LTC:momentum_wr': -62.85714285714228,\n",
       "  'bitstamp:/LTC:momentum_ao': 0.0,\n",
       "  'bitstamp:/LTC:momentum_kama': nan,\n",
       "  'bitstamp:/LTC:others_dr': -51.27312383060929,\n",
       "  'bitstamp:/LTC:others_dlr': nan,\n",
       "  'bitstamp:/LTC:others_cr': 0.0}}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "env.observer.feed.next()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
